package com.king.nio.filechannel;

import java.nio.ByteBuffer;

/**
 * @author king
 * @date 2020/12/27 15:00
 */
public class NioReadOnlyBuffer {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        for (int i = 0; i < 64; i++) {
            buffer.put((byte) i);
        }

        buffer.flip();

        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();

        while(readOnlyBuffer.hasRemaining()){
            System.out.println(readOnlyBuffer.get());
        }

        // ReadOnlyBufferException
        readOnlyBuffer.put((byte) 100);

    }
}
